package com.tanhua.server.controller;

import com.tanhua.domain.vo.AnswersVo;
import com.tanhua.domain.vo.QuestionnaireVo;
import com.tanhua.domain.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author:DD
 * @Date :2021/10/6 11:50
 * <p>
 * 测灵魂控制层
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;

    /**
     * 提交问卷
     */
    @PostMapping
    public ResponseEntity testSoul(@RequestBody Map<String,List<AnswersVo>> map) {
        List<AnswersVo> answerVos = map.get("answers");
        String id = testSoulService.submitTest(answerVos);
        return ResponseEntity.ok(id);
    }

    /**
     * 问卷列表查询
     * @return
     */
    @GetMapping
    public ResponseEntity questionnaireList()  {
        //根据用户id获取调查问卷数据
        List<QuestionnaireVo> result = testSoulService.findQuestionnaireListByUserId();
        return ResponseEntity.ok(result);
    }


    /**
     * 测灵魂查看结果
     * commentId:评论id
     */
    @RequestMapping(value = "/report/{id}", method = RequestMethod.GET)
    public ResponseEntity findReportById(@PathVariable("id") String id) {

        ReportVo reportVo = testSoulService.findReportById(id);

        return ResponseEntity.ok(reportVo);
    }
}
